﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="NewProduct.aspx.cs" Inherits="MonkeyWarranty.Web.WarrantyTickets.NewProduct" %>

<%@ Import Namespace="Resources" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <title>
        <%=GlobalStrings.WarrantyTicketForm %> - <%=GlobalStrings.WarrantyProduct %></title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="row">
        <div class="col-lg-12">
            <h3><%=GlobalStrings.AddNew %> <%=GlobalStrings.WarrantyProduct %></h3>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="alert alert-danger" runat="server" id="errorMessage" visible="False">
                <label class="control-label">
                    <asp:Literal ID="lblErrorMessage" runat="server"></asp:Literal></label>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <%=GlobalStrings.WarrantyProduct %>
                </div>
                <div class="panel-body">
                    <div class="col-lg-6">
                        <div class="form-group">
                            <asp:HiddenField ID="hidProductId" runat="server" />
                            <label><%=GlobalStrings.Code%></label>
                            <asp:TextBox ID="txtCode" runat="server" ReadOnly="True" CssClass="textEntry codeprefix"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtCode"
                                CssClass="failureNotification" ValidationGroup="AddNew">(*)</asp:RequiredFieldValidator>
                            <label><%=GlobalStrings.Name%></label>
                            <asp:TextBox ID="txtName" runat="server" ReadOnly="True" CssClass="textEntry name"></asp:TextBox>
                            <a href="javascript:void(0);" onclick="SelectProduct()" data-toggle="modal" data-target="#productModal"><i class="fa fa-2x fa-search"></i></a>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.Model %></label>
                            <asp:TextBox ID="txtModel" runat="server" CssClass="form-control"></asp:TextBox>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.Serial %></label>
                            <asp:TextBox ID="txtSerial" runat="server" CssClass="form-control"></asp:TextBox>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.Quantity %></label>
                            <asp:TextBox ID="txtQuantity" runat="server" CssClass="form-control" Text="1"></asp:TextBox>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.Accessary %></label>
                            <asp:TextBox ID="txtAccessary" runat="server" CssClass="form-control"></asp:TextBox>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.WarrantyDate %></label>
                            <asp:TextBox ID="txtWarrantyDate" runat="server" CssClass="form-control"></asp:TextBox>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.WarrantyMonth %></label>
                            <asp:TextBox ID="txtMonths" runat="server" CssClass="form-control" Text="0,0"></asp:TextBox>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.WarrantyCount %></label>
                            <asp:TextBox ID="txtWarrantyCount" runat="server" CssClass="form-control" Text="1"></asp:TextBox>
                        </div>
                    </div>
                    <div class="col-lg-6">
                        <div class="form-group">
                            <label><%=GlobalStrings.Manufacturers %></label>
                            <asp:DropDownList ID="ddlManufacturers1" runat="server" CssClass="form-control"></asp:DropDownList>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.Suppliers %></label>
                            <asp:DropDownList ID="ddlSuppliers" runat="server" CssClass="form-control"></asp:DropDownList>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.ServiceType %></label>
                            <asp:DropDownList ID="ddlWarrantyTypes" runat="server" CssClass="form-control"></asp:DropDownList>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.ErrorCode %></label>
                            <asp:DropDownList ID="ddlErrors" runat="server" CssClass="form-control"></asp:DropDownList>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.Description %></label>
                            <asp:TextBox ID="txtDescription" runat="server" TextMode="MultiLine" CssClass="form-control"></asp:TextBox>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.Note %></label>
                            <asp:TextBox ID="txtNote" TextMode="MultiLine" runat="server" CssClass="form-control"></asp:TextBox>
                        </div>
                    </div>
                    <div class="col-lg-12">
                        <asp:Button ID="btnSave" runat="server"
                            Text="<%$ Resources:GlobalStrings, Save %>" CssClass="btn btn-primary" Width="100px"
                            OnClick="btnSave_Click" />
                        <a class="btn btn-default" href="Edit.aspx?id=<%=Request.Params["ticketId"] %>#tabs-1"><%=GlobalStrings.Cancel %></a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- Product Modal -->
    <div class="modal fade" id="productModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width: 850px; height: 400px;">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel"><%=GlobalStrings.ProductsList %></h4>
                </div>
                <div class="modal-body">
                    <div class="form-inline">
                        <input class="form-control" type="text" id="name" placeholder="<%=GlobalStrings.Name %>" />
                        <%=GlobalStrings.ProductGroups %>:
                        <asp:DropDownList ID="ddlProductGroups" runat="server" CssClass="form-control"></asp:DropDownList>
                        <%=GlobalStrings.Manufacturers %>:
                            <asp:DropDownList ID="ddlManufacturers" runat="server" CssClass="form-control"></asp:DropDownList>
                        <button class="btn btn-default" type="button" id="LoadRecordsButton"><i class="fa fa-search"></i></button>
                        <button class="btn btn-default" type="button" id="ResetButton"><i class="fa fa-refresh"></i></button>
                    </div>
                    <p></p>
                    <div id="ProductsTableContainer"></div>
                    <p></p>
                    <a class="btn btn-success" href="../Products/New.aspx" target="_blank"><%=GlobalStrings.AddNew %></a>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->
    
    <script type="text/javascript">
        $(function () {
            $("#menu-warranty").addClass("active");
            $("#menu1-warranty").addClass("collapse in");
            $("#menu1-ticket").addClass("active");

            $("#<%=txtName.ClientID %>").prop("disabled", true);
            $("#<%=txtCode.ClientID %>").prop("disabled", true);
            $("#<%=txtWarrantyDate.ClientID %>").calendar({ timeSeparators: null });
            
            //Prepare jtable plugin
            $('#ProductsTableContainer').jtable({
                paging: true,
                pageSize: 10,
                sorting: true,
                defaultSorting: 'Name ASC',
                actions: {
                    listAction: '../Products/List.aspx/ProductListByFilter'
                },
                fields: {
                    Id: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    Code: {
                        title: '<%=GlobalStrings.Code %>',
                        list: false
                    },
                    Name: {
                        title: '<%=GlobalStrings.Name %>',
                        width: '20%',
                        display: function (data) {
                            return '<a href="javascript:void(0);" data-dismiss="modal" onclick="javascript:ProductSelect({Id:' + data.record.Id +
                            ',Code:\'' + data.record.Code + '\'' +
                                ',Name:\'' + escape(data.record.Name) + '\'' +
                                    '});">' + data.record.Name + '</a>';
                        }
                    }
                }
            });

            //Re-load records when user click 'load records' button.
            $('#LoadRecordsButton').click(function (e) {
                e.preventDefault();
                $('#ProductsTableContainer').jtable('load', {
                    name: $('#name').val(),
                    productGroupId: $('#<% = ddlProductGroups.ClientID %>').val(),
                    manufacturerId: $('#<% = ddlManufacturers.ClientID %>').val()
                });
            });

            // reset button
            $('#ResetButton').click(function (e) {
                e.preventDefault();
                $('#name').val('');
                $('#<% = ddlProductGroups.ClientID %>').val('0');
                $('#<% = ddlManufacturers.ClientID %>').val('0');
                $('#LoadRecordsButton').click();
            });
        });
    </script>

    <script type="text/javascript">
        function ProductSelect(product) {
            $("#<%=hidProductId.ClientID %>").val(product.Id);
            $("#<%=txtName.ClientID %>").val(unescape(product.Name));
            $("#<%=txtCode.ClientID %>").val(product.Code);
        }

        function SelectProduct() {
            // load data
            $('#LoadRecordsButton').click();
        }
    </script>
</asp:Content>
